const { lessorsModel } = require("./models/lessorsModel");



//获取出租方信息
module.exports.getLessors = async function ({ pageSize, currentPage }) {
    const nums = await lessorsModel.countDocuments();
    const data = await lessorsModel
        .find()
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    return {
        nums,
        data
    };
}

//查询
module.exports.searchLessors = async function (lessors) {
    const nums = (await lessorsModel.find({
        [lessors.type]: { $regex: lessors.value, $options: '$i' }
    })).length;
    //模糊查询
    const data = await lessorsModel
        .find({
            [lessors.type]: { $regex: lessors.value, $options: '$i' }
        })
        .limit(lessors.pageSize - 0)
        .skip((lessors.currentPage - 1) * lessors.pageSize);
    return {
        nums,
        data,

    };
}

//冻结账户
module.exports.frozenAccount = async function (frozen) {
    const data = await lessorsModel.updateOne({ _id: frozen._id }, { state: "2" });
    return data
}
//解冻账户
module.exports.thawAccount = async function (thaw) {
    const data = await lessorsModel.updateOne({ _id: thaw._id }, { state: "1" });
    return data
}